<template>
  <div class="shop-page">
    <!-- 顶部导航 -->
    <header class="header">
      <div class="container">
        <div class="logo">🐌 慢速商城</div>
        <nav class="nav">
          <a href="#">首页</a>
          <a href="#">分类</a>
          <a href="#">购物车</a>
          <a href="#">我的</a>
        </nav>
      </div>
    </header>

    <!-- 轮播图区域 - 未优化 -->
    <section class="banner-section">
      <div class="container">
        <div v-if="!banners" class="loading">加载中...</div>
        <div v-else class="banner-slider">
          <img 
            v-for="banner in banners" 
            :key="banner.id"
            :src="banner.image" 
            :alt="banner.title"
            class="banner-image"
          />
        </div>
      </div>
    </section>

    <!-- 商品列表 - 未优化 -->
    <section class="products-section">
      <div class="container">
        <h2 class="section-title">热门商品</h2>
        
        <div v-if="!products" class="loading">加载商品中...</div>
        
        <div v-else class="products-grid">
          <div v-for="product in products" :key="product.id" class="product-item">
            <ProductCard :product="product" :optimized="false" />
          </div>
        </div>
      </div>
    </section>

    <!-- 底部 -->
    <footer class="footer">
      <div class="container">
        <p>© 2025 慢速商城 - 未优化版本演示</p>
      </div>
    </footer>

    <!-- 性能提示 -->
    <div class="perf-hint">
      <h3>⚠️ 未优化版本</h3>
      <ul>
        <li>❌ 客户端渲染数据</li>
        <li>❌ 没有图片优化</li>
        <li>❌ 没有懒加载</li>
        <li>❌ 阻塞式加载</li>
        <li>❌ 没有骨架屏</li>
      </ul>
      <NuxtLink to="/shop-fast" class="compare-btn">
        查看优化版本 →
      </NuxtLink>
      <NuxtLink to="/" class="back-btn">
        ← 返回首页
      </NuxtLink>
    </div>
  </div>
</template>

<script setup lang="ts">
// ❌ 未优化：客户端请求数据
const banners = ref<any>(null)
const products = ref<any>(null)

onMounted(async () => {
  // ❌ 未优化：等待挂载后才请求
  // ❌ 未优化：串行请求
  const bannersData = await $fetch('/api/banners?delay=800')
  banners.value = bannersData.data
  
  const productsData = await $fetch('/api/products?delay=1000')
  products.value = productsData.data
})

// 设置页面元信息
useHead({
  title: '慢速商城 - 未优化版本',
  meta: [
    { name: 'description', content: '这是一个未优化的电商首页示例' }
  ]
})
</script>

<style scoped>
.shop-page {
  min-height: 100vh;
  background: #f5f5f5;
  padding-bottom: 100px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* 头部 */
.header {
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 60px;
}

.logo {
  font-size: 24px;
  font-weight: bold;
  color: #ff6b6b;
}

.nav {
  display: flex;
  gap: 30px;
}

.nav a {
  color: #333;
  text-decoration: none;
  transition: color 0.3s;
}

.nav a:hover {
  color: #ff6b6b;
}

/* 轮播图 */
.banner-section {
  background: white;
  padding: 20px 0;
  margin-bottom: 20px;
}

.banner-slider {
  display: flex;
  gap: 10px;
  overflow-x: auto;
}

.banner-image {
  width: 100%;
  max-width: 100%;
  height: 300px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}

/* 商品区域 */
.products-section {
  padding: 20px 0;
}

.section-title {
  font-size: 24px;
  color: #333;
  margin-bottom: 20px;
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
}

/* 加载状态 */
.loading {
  text-align: center;
  padding: 100px 20px;
  font-size: 18px;
  color: #999;
}

/* 底部 */
.footer {
  background: #333;
  color: white;
  padding: 30px 0;
  margin-top: 50px;
}

.footer p {
  text-align: center;
  margin: 0;
}

/* 性能提示 */
.perf-hint {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  max-width: 250px;
  border: 3px solid #ff6b6b;
}

.perf-hint h3 {
  margin: 0 0 15px 0;
  color: #ff6b6b;
  font-size: 16px;
}

.perf-hint ul {
  margin: 0 0 15px 0;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.8;
}

.compare-btn, .back-btn {
  display: block;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  text-align: center;
  padding: 10px;
  border-radius: 5px;
  text-decoration: none;
  font-weight: bold;
  transition: transform 0.3s;
  margin-bottom: 10px;
  font-size: 13px;
}

.compare-btn:hover, .back-btn:hover {
  transform: translateY(-2px);
}

.back-btn {
  background: #999;
}
</style>

